package com.ruoyi.ky450.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.ky450.domain.FixedFacilityElementInfo;
import com.ruoyi.ky450.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.ky450.domain.EquipBaseInfo;
import com.ruoyi.ky450.service.IEquipBaseInfoService;
import org.springframework.util.CollectionUtils;

/**
 * 装备基本信息Service业务层处理
 *
 * @author ruoyi
 * @date 2025-01-16
 */
@Service
public class EquipBaseInfoServiceImpl extends ServiceImpl<EquipBaseInfoMapper, EquipBaseInfo> implements IEquipBaseInfoService
{
    @Autowired
    private EquipBaseInfoMapper equipBaseInfoMapper;


    @Autowired
    private EquipRadarMapper radarMapper;

    @Autowired
    private EquipMissileMapper missileMapper;

    @Autowired
    private EquipAircraftMapper aircraftMapper;

    @Autowired
    private EquipArmoredVehicleMapper armoredVehicleMapper;

    @Autowired
    private EquipCannonMapper cannonMapper;

    @Autowired
    private EquipShipMapper shipMapper;
    /**
     * 查询装备基本信息
     *
     * @param id 装备基本信息主键
     * @return 装备基本信息
     */
    @Override
    public EquipBaseInfo selectEquipBaseInfoById(Long id)
    {

        return equipBaseInfoMapper.selectEquipBaseInfoById(id);
    }

    @Override
    public EquipBaseInfo selectEquipAllInfoById(Integer type,Long id) {
        EquipBaseInfo equipBaseInfo = equipBaseInfoMapper.selectById(id);
        if (equipBaseInfo == null){
            throw new ServiceException("装备id不存在："+id);
        }
//        0:雷达 1:导弹 2:飞机 3:舰船 4:火炮 5:装甲车
        switch (type){
            case 0:
                equipBaseInfo.setTAti(radarMapper.selectById(id));
                break;
            case 1:
                equipBaseInfo.setTAti(missileMapper.selectById(id));
                break;
            case 2:
                equipBaseInfo.setTAti(aircraftMapper.selectById(id));
                break;
            case 3:
                equipBaseInfo.setTAti(shipMapper.selectById(id));
                break;
            case 4:
                equipBaseInfo.setTAti(cannonMapper.selectById(id));
                break;
            case 5:
                equipBaseInfo.setTAti(armoredVehicleMapper.selectById(id));
                break;
            default:
                break;
        }
        return equipBaseInfo;
    }

    /**
     * 查询装备基本信息列表
     *
     * @param equipBaseInfo 装备基本信息
     * @return 装备基本信息
     */
    @Override
    public List<EquipBaseInfo> selectEquipBaseInfoList(EquipBaseInfo equipBaseInfo)
    {
        return equipBaseInfoMapper.selectEquipBaseInfoList(equipBaseInfo);
    }

    /**
     * 新增装备基本信息
     *
     * @param equipBaseInfo 装备基本信息
     * @return 结果
     */
    @Override
    public int insertEquipBaseInfo(EquipBaseInfo equipBaseInfo)
    {
        equipBaseInfo.setCreateTime(DateUtils.getNowDate());
        return equipBaseInfoMapper.insert(equipBaseInfo);
    }

    /**
     * 修改装备基本信息
     *
     * @param equipBaseInfo 装备基本信息
     * @return 结果
     */
    @Override
    public int updateEquipBaseInfo(EquipBaseInfo equipBaseInfo)
    {
        equipBaseInfo.setUpdateTime(DateUtils.getNowDate());
        return equipBaseInfoMapper.updateEquipBaseInfo(equipBaseInfo);
    }

    /**
     * 批量删除装备基本信息
     *
     * @param ids 需要删除的装备基本信息主键
     * @return 结果
     */
    @Override
    public int deleteEquipBaseInfoByIds(Integer[] ids)
    {
        return equipBaseInfoMapper.deleteEquipBaseInfoByIds(ids);
    }

    /**
     * 删除装备基本信息信息
     *
     * @param targetId 装备基本信息主键
     * @return 结果
     */
    @Override
    public int deleteEquipBaseInfoById(Integer type,Long targetId)
    {
//        装备类型(0:雷达 1:导弹 2:飞机 3:舰船 4:火炮 5:装甲车)
        switch (type) {
            case 0:
                radarMapper.deleteById(targetId);
                break;
            case 1:
                missileMapper.deleteById(targetId);
                break;
            case 2:
                aircraftMapper.deleteById(targetId);
                break;
            case 3:
                shipMapper.deleteById(targetId);
                break;
            case 4:
                cannonMapper.deleteById(targetId);
                break;
            case 5:
                armoredVehicleMapper.deleteById(targetId);
                break;
            default:
                break;
        }
        return equipBaseInfoMapper.deleteById(targetId);
    }

    @Override
    public EquipBaseInfo getEquipBaseInfoByTBInfoId(Long id) {
        QueryWrapper<EquipBaseInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("target_base_info_id", id);
        List<EquipBaseInfo> list = list(wrapper);
        if(!CollectionUtils.isEmpty(list)){
            return list.get(0);
        }
        return null;
    }
}
